package com.example.petcare.controller.provider;

import com.example.petcare.pojo.*;
import com.example.petcare.service.OrderPhotoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController//标记为控制器类,并且返回json数据
@RequestMapping("/provider/photo")//请求路径
@Slf4j
public class OrderPhotoController {

    @Autowired
    private OrderPhotoService orderPhotoService;

    // 添加订单照片（早中晚）
    @PostMapping
    public Result addPet(@RequestBody OrderPhoto orderPhoto) {
        orderPhotoService.addOrderPhoto(orderPhoto);
        return Result.success();
    }

    // 获取记录表(条件分页)
    @GetMapping("/byDate")
    public Result<PageBean<OrderPhoto>> getPhotosByDate(
            Integer pageNum,
            Integer pageSize,
            @RequestParam Integer hostId,
            @RequestParam(required = false) String recordDate) {

        // 如果有日期传入
        LocalDate localDate = null;
        if (recordDate != null && !recordDate.isEmpty()) {
            localDate = LocalDate.parse(recordDate);
            System.out.println("localDate = " + localDate);
        }

        System.out.println("localDate = " + localDate);

        PageBean<OrderPhoto> pageBean = orderPhotoService.getPhotosByDate(pageNum, pageSize, hostId, localDate);
        return Result.success(pageBean);

    }


}


